package com.project.restaurant.order.dao;

import com.project.restaurant.order.dto.DetailOrder;
import com.project.restaurant.order.typehandler.OrderStateTypeHandler;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DetailOrderDao {

    @Results(id = "DetailOrderResultMap",value = {
            @Result(column = "order_id",property = "orderId"),
            @Result(column = "order_state",property = "orderState",typeHandler = OrderStateTypeHandler.class),
            @Result(property = "seat",one = @One(resultMap = "com.project.restaurant.mapper.SeatMapper.seatResultMap")),
            @Result(column = "order_id",property = "orderItems",
                    many = @Many(select = "com.project.restaurant.order.dao.OrderItemDao.selectByOrderId"))
    })
    @Select("select o.order_id,o.total_price,o.order_state,o.order_purchase_time," +
            "o.seat_id,o.order_demand,o.transaction_id," +
            "s.seat_name,s.max_people_num " +
            "from `order` o " +
            "left join seat s on o.seat_id = s.seat_id " +
            "where o.order_id = #{orderId} and o.user_id =#{userId}")
    DetailOrder selectById(@Param("orderId") String orderId,@Param("userId") Long userId);
}
